import 'package:color_dart/RgbaColor.dart';
import 'package:flutter/material.dart';
import 'package:im_flutter_sdk_example/components/empty_list.dart';
import 'package:im_flutter_sdk_example/components/labels/index.dart';
import 'package:im_flutter_sdk_example/jsonserialize/attention/data.dart';
import 'package:im_flutter_sdk_example/mock/data.dart';
import 'package:im_flutter_sdk_example/utils/global.dart';

import 'widgets/attention.dart';

class AttentionList extends StatefulWidget {
  AttentionList({Key key}) : super(key: key);

  @override
  _AttentionListState createState() => _AttentionListState();
}

class _AttentionListState extends State<AttentionList> {
  List<AttentionData> attentionData = [];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('我的关注')),
      body: EmptyList(),
      // body: Container(
      //   color: rgba(245, 245, 245, 1),
      //   constraints: BoxConstraints(
      //     minHeight: MediaQuery.of(context).size.height,
      //   ),
      //   child: Column(
      //     children: [
      //       Container(),
      //       Container(
      //         color: rgba(255, 255, 255, 1),
      //         child: SingleChildScrollView(
      //             child: Column(
      //           children: [
      //             ...attentionData
      //                 .asMap()
      //                 .keys
      //                 .map((idx) => AttentionItem(
      //                     item: attentionData[idx],
      //                     handleAttention: tapAttention,
      //                     index: idx,
      //                     isLast: idx == attentionData.length - 1))
      //                 .toList(),
      //             LabelFooter(title: '200位关注好友')
      //           ],
      //         )),
      //       ),
      //     ],
      //   ),
      // ),
    );
  }

  @override
  void initState() {
    super.initState();
    this.getData();
  }

  void getData() async {
    MockData.attentionData.forEach((e) {
      AttentionData attentionItem = AttentionData.fromJson(e);
      attentionData.add(attentionItem);
    });
  }

  //点击关注/取消关注
  tapAttention(followState, index) {
    print(followState);
    print(index);

    setState(() {
      this.attentionData[index].follow = !this.attentionData[index].follow;
    });
    if (followState) {
      G.toast('取消关注');
    } else {
      G.toast('关注成功');
    }
  }
}
